#include <algorithm>
#include <cctype>
#include <cstdio>
#include <vector>

#define lld long long
#define ENDL '\n'

inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + (ch - '0');
    ch = getchar();
  }
  return x * f;
}

inline void write(lld x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + '0');
}

void solve() {
  int n;
  // int n = read();
  scanf("%d", &n);
  std::vector<int> a(2 * n);
  for (int i = 0; i < 2 * n; ++i) {
    // a[i] = read();
    scanf("%d", &a[i]);
  }
  std::sort(a.begin(), a.end());
  lld sum = 0;
  for (int i = 0; i < 2 * n; i += 2) {
    lld diff = a[i + 1] - a[i];
    sum += diff * diff;
  }
  printf("%lld\n", sum);
  /* write(sum);
  putchar('\n'); */
}

int main() {
  // int T = read();
  int T;
  scanf("%d", &T);
  while (T--) {
    solve();
  }
  return 0;
}